using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
using BLL;
using DTO;
using System.IO;
using BLL.Store;
using System.ComponentModel;

public partial class ShoppingCart : BasePage
{
    int id = 0;
    Product product = null;
    protected void Page_Init(object sender, EventArgs e)
    {
        
    }
    private void Page_Load(object sender, System.EventArgs e)
    {       
        id = int.Parse(this.Request.QueryString["ID"]);
        product = Product.GetProductByID(id);
        Panel1.Visible = product.DiscountPercentage > 0;
        Panel2.Visible = !Panel1.Visible;
        if (product.DiscountPercentage > 0)
        {
            lblGiaGoc.Text = product.StringUnitPrice;
            lblGiamgia.Text = product.FinalUnitPrice.ToString() + "%";
            lblGiaKM.Text = product.StringDiscountPercentage;
        }
        else
        {
            lblGia.Text = product.StringFinalUnitPrice;
        }
        lblTitle.Text = product.Title;
        lblGia.Text = product.UnitPrice.ToString("#0,000") + " VND";
        //Image.ImageUrl = product.SmallImageUrl;
        lblTotal.Text = product.DiscountPercentage.ToString("#0,000") + " VND";
    }
    protected void txtDatHang_Click(object sender, EventArgs e)
    {
        int ret = 0;
        decimal total = (product.DiscountPercentage * int.Parse(ddlNumber.SelectedValue));
        ret = Order.InsertOrder(id, 1, ddlNumber.SelectedValue, total, txtName.Text, txtPhone.Text, txtEmail.Text, txtGhichu.Text);
        if (ret > 0)
        {
            lblThongbao.Visible = true;
        }
    }
    protected void txtTT_Click(object sender, EventArgs e)
    {
        Response.Redirect(Globals.ApplicationPath + "Products/" + id + "/" + Utils.ConvertToUnSign(product.Title) + ".aspx");
    }
    protected void ddlNumber_OnSelectedIndexChanged(object sender, EventArgs e)
    {
        lblTotal.Text = (product.DiscountPercentage * int.Parse(ddlNumber.SelectedValue)).ToString("#0,000") + " VND";
    }
}
